home *** CD-ROM | disk | FTP | other *** search
Wrap
GW-BASIC | 1984-05-28 | 11.8 KB | 369 lines
1 REM FUNCTION PLOT COPYRIGHT (C) 1983 BY HUGH CALVIN 2 REM 3 REM *** FUNCTION PLOT *** IS A PORTION OF PC CUSTOM SOFTWARE'S 4 REM GRAPHICS PACKAGE FOR THE IBM PC 5 REM 6 REM VERSION 1.2 *** AUTHOR HUGH CALVIN *** 4/10/83 7 REM 8 REM 9 REM 10 ' ...Advanced feature...begin here with program to evaluate function coefficients 15 ' 95 ' ...Advanced feature...end here with ... 95 goto 3000 ... 99 ' ...Function definitions begin on line 100 100 GOTO 1000 950 ' ...Function definitions end here 999 IF NOT CALLED% THEN 3000 ELSE CALLED%=0:RETURN 1000 IF SKIP% THEN GOTO 3000 ELSE SKIP%=-1:CLS:KEY OFF:WIDTH 80 1001 A$="This is FUNCTION PLOT, a character plotting routine for the IBM PC." 1002 B$="Version 1.2 (C) Copyright Hugh A. Calvin, 1982" 1003 LOCATE 7,7:PRINT A$ 1004 LOCATE 9,17:PRINT B$ 1005 FOR I=1 TO 5000:NEXT I 1006 CLS 3000 REM Function Plot routine 3005 REM 3010 ON ERROR GOTO 0:TAB$="no" 3015 CLS:A$="FUNCTION PLOT MENU":LOCATE 2:PRINT TAB(31) A$ 3020 A$="Selection Description" 3025 LOCATE 7:PRINT TAB(40-LEN(A$)/2) A$ 3029 LOCATE 9,31:PRINT "1 Define function" 3030 LOCATE 10,31:PRINT "2 Plot function" 3035 LOCATE 11,31:PRINT "3 Review function" 3040 LOCATE 12,31:PRINT "4 Tabulate function" 3045 LOCATE 13,31:PRINT "5 Printer plot function" 3050 LOCATE 14,31:PRINT "6 Save function on diskette" 3055 LOCATE 15,31:PRINT "7 Enter start and stop data" 3060 LOCATE 16,31:PRINT "8 Select plot symbols" 3065 LOCATE 17,31:PRINT "9 Enter plot labels" 3070 LOCATE 18,31:PRINT "Esc Return to Start" 3075 LOCATE 19,31:PRINT "X Return to DOS" 3080 REM 3085 REM 3090 REM 3095 LOCATE 21:A$="What is your selection?":PRINT TAB(40-LEN(A$)/2) A$ 3100 A$=INKEY$:IF A$="" THEN 3100 3105 IF A$=CHR$(88) OR A$=CHR$(120) THEN SYSTEM 3110 IF A$=CHR$(27) THEN 9 3115 IF LEN(A$)=1 THEN SEL1=VAL(A$) ELSE SEL1=0 3120 IF SEL1<1 OR SEL1>9 THEN FOR II%=1 TO 15:A$=INKEY$:NEXT II%:GOTO 3095 3125 CLS:ON SEL1 GOTO 3135,3285,4280,4360,3285,4310,3440,3345,3290 3130 REM 3135 CLS:A$="DEFINE FUNCTION":LOCATE 2:PRINT TAB(40-LEN(A$)/2) A$ 3140 A$="Selection Definition":LOCATE 6:PRINT TAB(40-LEN(A$)/2) A$ 3145 A$="1 Type in function(s)":LOCATE 8,31:PRINT A$ 3150 A$="2 Read in function(s)":LOCATE 10,31:PRINT A$ 3155 A$="Esc Return to Menu":LOCATE 12,31:PRINT A$ 3160 A$="What is your selection?":LOCATE 15:PRINT TAB(40-LEN(A$)/2) A$ 3165 A$=INKEY$:IF A$="" THEN 3165 3170 IF A$=CHR$(27) THEN 3000 3175 IF LEN(A$)=1 THEN SEL3=VAL(A$) ELSE SEL3=0 3180 IF SEL3<1 OR SEL3>2 THEN 3160 3185 ON SEL3 GOTO 3195,3230 3190 REM 3195 REM Type in function 3200 REM 3205 A$="Type your function in BASIC beginning with line 100 and ending before line 950, then PRESS F2. Up to four functions may be entered, y1=fn1(x), y2=fn2(x), etc. 3210 CLS:PRINT A$:END 3215 REM 3220 REM Merge user file containing functions 3225 REM 3230 ON ERROR GOTO 0:CLS:PRINT "READ IN FUNCTION...";:LOCATE 4,1:GOSUB 10000 3232 INPUT "Which drive contains your function diskette ? (a or b) ",D$:PRINT :PRINT :PRINT :IF D$="" THEN D$="A" 3233 IF D$="a" OR D$="b" THEN 3235 3234 IF D$="A" OR D$="B" THEN 3235 ELSE 3232 3235 INPUT "What is the name of the function (.FN) file you wish to read in ? ",FILE$:IF LEN(FILE$)>7 THEN PRINT "Filename must be less than 8 characters":GOTO 3235 3250 FILSPC$=D$+":"+FILE$+".fn":RES%=1:ON ERROR GOTO 20000:OPEN "I",1,FILSPC$:CLOSE #1:ON ERROR GOTO 0 3255 CHAIN MERGE FILSPC$,10,DELETE 10-950 3260 CLS:PRINT A$:END 3265 REM 3270 REM ...Collect auxilliary information... 3275 REM 3280 REM Title,x- and y- axis label definition 3285 IF TIDEF$="yes" THEN 3330 3290 CLS:PRINT "PLOT LABEL DEFINITION";:LOCATE 2,1:GOSUB 10000 3295 INPUT "Enter plot title"; TITLE$:IF LEN(TITLE$)>60 THEN PRINT "Title must be <60 characters long":GOTO 3295 3300 INPUT "Enter y-axis label"; YLAB$:IF LEN(YLAB$)>20 THEN PRINT "Y label must be <20 characters long":GOTO 3300 3305 INPUT "Enter x-axis label"; XLAB$:IF LEN(XLAB$)>60 THEN PRINT "X label must be <60 characters long":GOTO 3305 3310 TIDEF$="yes" 3315 IF SEL1=5 THEN 3330 3320 IF SEL1<>2 THEN 3000 3325 REM 3330 REM Plot symbol definition 3335 REM 3340 IF SYMDEF$="yes" THEN 3410 3345 CLS:A$="PLOT SYMBOL DEFINITION":LOCATE 2:PRINT A$;:LOCATE 3,1:GOSUB 10000 3350 INPUT "Enter plot symbol for y1(*)",PS$:IF PS$="" THEN SYM$(0)="*":GOTO 3365 3355 IF LEN(PS$)>1 THEN PRINT "Enter 1 character":GOTO 3350 3360 SYM$(0)=PS$ 3365 INPUT "Enter plot symbol for y2(x)",PS$:IF PS$="" THEN SYM$(1)="x":GOTO 3380 3370 IF LEN(PS$)>1 THEN PRINT "Enter 1 character":GOTO 3365 3375 SYM$(1)=PS$ 3380 INPUT "Enter plot symbol for y3(+)",PS$:IF PS$="" THEN SYM$(2)="+":GOTO 3395 3385 IF LEN(PS$)>1 THEN PRINT "Enter 1 character":GOTO 3380 3390 SYM$(2)=PS$ 3395 INPUT "Enter plot symbol for y4(#)",PS$:IF PS$="" THEN SYM$(3)="#":GOTO 3410 3400 IF LEN(PS$)>1 THEN PRINT "Enter 1 character":GOTO 3395 3405 SYM$(3)=PS$ 3410 SYMDEF$="yes":IF SEL1=5 THEN 3435 3415 IF SEL1<>2 THEN 3000 3420 REM 3425 REM Start and stop definition 3430 REM 3435 IF XDEF$="yes" THEN 3765 3440 CLS:PRINT "X-AXIS DATA";:LOCATE 2,1:GOSUB 10000:INPUT "Enter start value:"; X0 3445 INPUT "Enter stop value:"; X2 3450 IF X0=>X2 THEN 3440 3455 XDEF$="yes" 3460 REM 3465 REM Determine function minima and maxima 3470 REM 3475 FOR I=0 TO 3:MINI(I)=1E+38:MAXI(I)=-1E+38:NEXT I 3480 X3=(X2-X0)/60:R=10 3485 FOR T1=X0 TO X2+X3/2 STEP X3 3490 CALLED%=-1:X=T1:GOSUB 100 3495 IF MINI(0)>Y1 THEN MINI(0)=Y1 3500 IF MAXI(0)<Y1 THEN MAXI(0)=Y1 3505 IF MINI(1)>Y2 THEN MINI(1)=Y2 3510 IF MAXI(1)<Y2 THEN MAXI(1)=Y2 3515 IF MINI(2)>Y3 THEN MINI(2)=Y3 3520 IF MAXI(2)<Y3 THEN MAXI(2)=Y3 3525 IF MINI(3)>Y4 THEN MINI(3)=Y4 3530 IF MAXI(3)<Y4 THEN MAXI(3)=Y4 3535 NEXT T1 3540 REM 3545 REM NFNS is the number of functions and IN is the function number if a single function is calculated... 3550 REM 3555 NFNS=0:IN=0: FOR I=0 TO 3:IF MINI(I)=MAXI(I) THEN 3570 3560 NFNS=NFNS+1 3565 IN=I 3570 NEXT I 3575 IF TAB$="yes" THEN 4415 3580 REM establish the type of plot frame 3585 REM 3590 REM PLUMIN$ indicates whether there are plus and minus components to be plotted 3595 REM 3600 PLUMIN$="no":ALPLUS$="yes" 3605 FOR I=0 TO NFNS-1:IF MAXI(I)>0 AND MINI(I)<0 THEN PLUMIN$="yes" 3610 NEXT I 3615 REM 3620 REM if any function has components <0 then alplus$=no, ie not all of the functions are positive 3625 REM 3630 FOR I=0 TO NFNS-1:IF MINI(I)<0 THEN ALPLUS$="no" 3635 NEXT I 3640 REM 3645 REM check to see if there are functions which are all positive and all negative 3650 REM 3655 FOR I=0 TO NFNS-1:IF MINI(I)>=0 THEN POSI$="yes" 3660 FOR J=0 TO NFNS-1:IF MAXI(J)<=0 THEN NEGI$="yes" 3665 NEXT J:IF POSI$="yes" AND NEGI$="yes" THEN PLUMIN$="yes" 3670 NEXT I 3675 REM check to see if there are functions which are all positive and all negative 3680 REM 3685 REM choose plot frame 3690 REM 3695 IF NFNS>1 AND PLUMIN$="yes" THEN XAXIS=12:GOTO 3765 3700 IF NFNS=1 THEN 3715 3705 IF ALPLUS$="yes" THEN XAXIS=22:GOTO 3765 3710 XAXIS=2:GOTO 3765 3715 IF MAXI(IN)<=ABS(MINI(IN)) THEN 3740 3720 RATIO=ABS(MINI(IN))/MAXI(IN) 3725 IF MINI(IN)=>0 THEN XAXIS=22:GOTO 3765 3730 IF RATIO<0.34 THEN XAXIS=17:GOTO 3765 3735 XAXIS=12:GOTO 3765 3740 RAT=ABS(MAXI(IN))/ABS(MINI(IN)) 3745 IF MAXI(IN)<=0 THEN XAXIS=2:GOTO 3765 3750 IF RAT<0.34 THEN XAXIS=7:GOTO 3765 3755 XAXIS=12:GOTO 3765 3760 REM 3765 IF SEL1=5 THEN 3790 3770 IF SEL1<>2 THEN 3000 3775 REM 3780 REM plot axis labels 3785 REM 3790 CLS:FOR I=1 TO 50:LOCATE 5,10:PRINT "Hit ..Esc.. to return to Menu ":NEXT I 3795 YL=LEN(YLAB$):XL=LEN(XLAB$):PL=LEN(TITLE$):CLS 3800 LOCATE 25,1:PRINT TAB(40-CINT(XL/2)) XLAB$ 3805 LOCATE 1,14:PRINT TAB(40-CINT(PL/2)) TITLE$ 3810 YSTART=12-CINT(YL/2) 3815 FOR I=0 TO YL-1:LOCATE I+YSTART,2:PRINT MID$(YLAB$,I+1,1):NEXT I 3820 LOCATE 1,14:PRINT TAB(40-CINT(PL/2)) TITLE$ 3825 REM 3830 REM plot the axes (or frame) 3835 REM 3840 FULL$="yes" 3845 REM 3850 REM change full$ to "yes" to get a boxed in frame 3855 REM 3860 FOR I=2 TO 22:LOCATE I,10:IF((I+3) MOD 5)=0 THEN PRINT "+" ELSE PRINT "|" 3865 NEXT I 3870 FOR I=11 TO 70:LOCATE XAXIS,I:IF(I MOD 10)=0 THEN PRINT "+" ELSE PRINT "-" 3875 NEXT I 3880 IF FULL$="no" THEN 3920 3885 FOR I=2 TO 22:LOCATE I,70:IF((I+3) MOD 5)=0 THEN PRINT "+" ELSE PRINT "|" 3890 NEXT I 3895 FOR I=11 TO 70:LOCATE 2,I:IF (I MOD 10)=0 THEN PRINT "+"ELSE PRINT "-" 3900 NEXT I 3905 FOR I=11 TO 70:LOCATE 22,I:IF (I MOD 10)=0 THEN PRINT "+" ELSE PRINT "-" 3910 NEXT I 3915 REM 3920 REM 3925 REM PRINT AXIS SCALES--Y-AXIS 3930 REM 3935 IF XAXIS=22 THEN FOR I=0 TO 4:SCALEY(I)=I*0.25:NEXT I 3940 IF XAXIS=17 THEN FOR I=0 TO 4:SCALEY(I)=(I-1)/3:NEXT I 3945 IF XAXIS=12 THEN FOR I=0 TO 4:SCALEY(I)=-1+I*0.5:NEXT I 3950 IF XAXIS=7 THEN FOR I=0 TO 4:SCALEY(I)=(I-3)/3:NEXT I 3955 IF XAXIS=2 THEN FOR I=0 TO 4:SCALEY(I)=-1+I*0.25:NEXT I 3960 FOR I=0 TO 4:LOCATE I*5+2,4:PRINT USING"##.##";SCALEY(4-I):NEXT I 3965 REM 3970 REM x-axis scale 3975 REM 3977 X4=X2:IF ABS(X0)>ABS(X2) THEN X4=ABS(X0) 3980 FOR I=-6 TO 6:J=10^I 3985 IF X4/J<1 THEN 3995 3990 DEC=J 3995 NEXT I 4000 INCR=(X2-X0)/(6*DEC) 4005 FOR I=0 TO 6:LOCATE 23,6+I*10:PRINT USING"##.##";(X0/DEC)+I*INCR:NEXT I 4010 LOCATE 23,71:PRINT USING "##.#^^^^";DEC:LOCATE 23,71:PRINT "x" 4015 REM 4020 REM 4025 REM 4030 REM define the normalization constants 4035 FOR I=0 TO 3 4040 IF MAXI(I)=MINI(I) THEN NORM(I)=1E+38:GOTO 4050 4045 IF MAXI(I)=>ABS(MINI(I)) THEN NORM(I)=MAXI(I) ELSE NORM(I)=ABS(MINI(I)) 4050 NEXT I 4055 N1=NORM(0):N2=NORM(1):N3=NORM(2):N4=NORM(3) 4060 REM 4065 REM plot the normalized functions 4070 REM 4075 IF MAXI(0)=>ABS(MINI(GV)) THEN DELTAY=XAXIS-2 ELSE DELTAY=22-XAXIS 4080 K=-1:FOR I=X0 TO X2+X3/2 STEP X3:X=I:CALLED%=-1:GOSUB 100 4085 S1=Y1/N1:S2=Y2/N2:S3=Y3/N3:S4=Y4/N4 4090 K=K+1 4095 IF N1=1E+38 THEN 4110 4100 Y1PLT=CINT(XAXIS-S1*DELTAY) 4105 LOCATE Y1PLT,K+10:PRINT SYM$(0) 4110 IF N2=1E+38 THEN 4125 4115 Y2PLT=CINT(XAXIS-S2*DELTAY) 4120 LOCATE Y2PLT,K+10:PRINT SYM$(1) 4125 IF N3=1E+38 THEN 4140 4130 Y3PLT=CINT(XAXIS-S3*DELTAY) 4135 LOCATE Y3PLT,K+10:PRINT SYM$(2) 4140 IF N4=1E+38 THEN 4155 4145 Y4PLT=CINT(XAXIS-S4*DELTAY) 4150 LOCATE Y4PLT,K+10:PRINT SYM$(3) 4155 NEXT I 4160 REM 4165 REM list maxima and minima for each function 4170 REM 4175 LOCATE 2,73:PRINT "Min/Max" 4180 K=0:FOR I=0 TO NFNS-1 4185 LOCATE 4+K,74:PRINT SYM$(I) 4190 LOCATE 5+K,72:PRINT USING "#####.##";MINI(I) 4195 LOCATE 6+K,72:PRINT USING "#####.##";MAXI(I) 4200 K=K+4 4205 NEXT I 4210 REM 4215 REM ... printer plot 4220 REM 4225 IF SEL1<>5 THEN 4270 4229 ' ****following escape sequence turns on compressed character mode for an EPSON MX printer**** 4230 LPRINT CHR$(15) 4235 HOLDING.PLACE.! = 0 4240 PRINT.SCREEN = VARPTR(HOLDING.PLACE.!) 4245 POKE PRINT.SCREEN+0, 205 4250 POKE PRINT.SCREEN+1, 5 4255 POKE PRINT.SCREEN+2, 203 4260 CALL PRINT.SCREEN 4264 ' ****following escape sequence turns off compressed character mode for an EPSON MX printer**** 4265 LPRINT CHR$(27) CHR$(146) 4270 A$=INKEY$:IF A$="" THEN 4270 4275 IF A$=CHR$(27) THEN 3000 ELSE 4270 4280 REM ...review function 4285 CLS:PRINT "REVIEW FUNCTION...to continue, PRESS F2":PRINT:PRINT:PRINT 4290 LIST 100-950 4295 A$=INKEY$:IF A$="" THEN 4295 4300 IF A$=CHR$(27) THEN 3000 ELSE 4295 4305 REM 4310 REM ...save file on diskette 4312 ON ERROR GOTO 0:CLS:PRINT "SAVE FUNCTION(S)";:LOCATE 4,1:GOSUB 10000 4315 INPUT "Which drive contains your function diskette ? (a or b) ",D$:PRINT :PRINT :PRINT :IF D$="" THEN D$="A" 4316 IF D$="a" OR D$="b" THEN 4320 4317 IF D$="A" OR D$="B" THEN 4320 ELSE 4315 4320 INPUT "What do you want to name the file where the function(s) will be saved?",FILE$ 4335 FILSPC$=D$+":"+FILE$+".fn":RES%=2:ON ERROR GOTO 20000:OPEN "O",1,FILSPC$:CLOSE #1:ON ERROR GOTO 0 4337 PRINT:PRINT:PRINT " PRESS F2 to return to the menu." 4340 LIST 10-950,FILSPC$ 4345 A$=INKEY$:IF A$="" THEN 4345 4350 IF A$=CHR$(27) THEN 3000 ELSE 4345 4355 REM 4360 REM ...tabulate function(s) 4365 REM 4370 CLS:PRINT "X-AXIS DATA";:LOCATE 2,1:GOSUB 10000:INPUT "Enter start value:"; X0 4375 INPUT "Enter stop value:"; X2 4380 INPUT "Enter step size:";X4 4385 IF X0=>X2 THEN 4370 4390 IF X4=0 THEN X4=(X2-X0)/50 4395 INPUT "Enter Title Line 1: ",TI1$ 4400 INPUT "Enter Title Line 2: ",TI2$ 4405 PRINT : PRINT "Preparing tabulation..." :PRINT "Make sure the printer is on" 4410 R=10:TAB$="yes":GOTO 3480 4415 IF NFNS=1 THEN B$=STRING$(24,"="):C=10:GOTO 4435 4420 IF NFNS=2 THEN B$=STRING$(38,"="):C=20:GOTO 4435 4425 IF NFNS=3 THEN B$=STRING$(52,"="):C=30:GOTO 4435 4430 IF NFNS=4 THEN B$=STRING$(66,"="):C=40 4435 K=1 'k is the line counter 4440 FOR T1=X0 TO X2+X4/2 STEP X4 4445 IF K<>1 THEN 4505 4450 CKTI=0:IF (C-LEN(TI1$)/2)<0 THEN INPUT "Title Line 1 too long -- enter new title: ", TI1$: CKTI=1 4455 IF (C-LEN(TI2$)/2)<0 THEN INPUT "Title Line 2 too long -- enter new title: ",TI2$: CKTI=1 4460 IF CKTI=1 THEN GOTO 4450 4465 LPRINT CHR$(12) 4470 LPRINT:LPRINT:LPRINT TAB(C-LEN(TI1$)/2) TI1$:LPRINT TAB(C-LEN(TI2$)/2) TI2$ 4475 LPRINT B$ 4480 IF NFNS=1 THEN LPRINT "x","y1" 4485 IF NFNS=2 THEN LPRINT "x","y1","y2" 4490 IF NFNS=3 THEN LPRINT "x","y1","y2","y3" 4495 IF NFNS=4 THEN LPRINT "x","y1","y2","y3","y4" 4500 LPRINT B$:LPRINT 4505 CALLED%=-1:X=T1:K=K+1:GOSUB 100 4510 IF NFNS=1 THEN LPRINT USING "##.###^^^^ "; X,Y1 4515 IF NFNS=2 THEN LPRINT USING "##.###^^^^ "; X,Y1,Y2 4520 IF NFNS=3 THEN LPRINT USING "##.###^^^^ "; X,Y1,Y2,Y3 4525 IF NFNS=4 THEN LPRINT USING "##.###^^^^ "; X,Y1,Y2,Y3,Y4 4530 IF K<52 THEN 4545 4535 LPRINT CHR$(12) 4540 K=1 4545 NEXT T1 4550 PRINT "TABULATION COMPLETE...hit Esc to return to menu" 4555 A$=INKEY$:IF A$="" THEN 4555 4560 IF A$=CHR$(27) THEN R=0:GOTO 3000 4561 GOTO 4555 4565 END 10000 YY%=CSRLIN 10010 PRINT "Press <Esc> to return to Main Menu or <Return> to continue... "; 10020 A$=INKEY$:IF A$="" THEN 10020 10030 IF A$=CHR$(27) THEN PRINT "Esc";:RETURN 3000 10040 IF A$=CHR$(13) THEN LOCATE YY%,1:PRINT STRING$(79," ");:LOCATE YY%,1:GOTO 10099 10050 BEEP:FOR II%=1 TO 15:A$=INKEY$:NEXT II%:GOTO 10020 10099 RETURN 20000 'ERROR TRAP FOR DISK READS AND WRITES 20010 IF ERR=53 THEN MSG$="File not found":GOTO 20100 20020 IF ERR=61 THEN MSG$="Disk full":GOTO 20100 20030 IF ERR=67 THEN MSG$="Too many files":GOTO 20100 20040 IF ERR=68 THEN MSG$="Device Unavailable":GOTO 20100 20050 IF ERR=70 THEN MSG$="Disk Write Protect":GOTO 20100 20060 IF ERR=71 THEN MSG$="Disk not Ready":GOTO 20100 20070 IF ERR=72 THEN MSG$="Disk Media":GOTO 20100 20080 LOCATE 23,1:PRINT "Error #";ERR;" has occurred in line";ERL;" -- Returning to Basic.";:END 20100 LOCATE 23,1:PRINT "A ";MSG$;" has occurred." 20110 PRINT "Press <Return> to try again or <Esc> to return to Main Menu"; 20120 A$=INKEY$:IF A$="" THEN 20120 20130 IF A$=CHR$(27) THEN RESUME 3000 20140 IF A$=CHR$(13) THEN 20200 20150 BEEP:FOR II%=1 TO 15:A$=INKEY$:NEXT II%:GOTO 20120 20200 IF RES%=1 THEN RESUME 3230 ELSE RESUME 4312